var editThemes = {
    zbjall: "Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,Separator,SelectAll,Removeformat,Separator,Align,List,Outdent,Indent,Separator,Link,Unlink,Img,Separator,Table,Emot",
    zbjmin: "Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,Separator,SelectAll,Removeformat,Separator,Align,List,Outdent,Indent,Separator,Link,Unlink,Img,Separator,Table",
    zbjtxt: "Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,Separator,SelectAll,Removeformat,Separator,Align,List,Outdent,Indent,Separator,Link,Unlink"
};
function editTools($) {
    if ($.xheditor) return false;
    $.fn.xheditor = function(options) {
        var arrSuccess = [];
        this.each(function() {
            if (!$.nodeName(this, "TEXTAREA")) return;
            if (options === false) {
                if (this.xheditor) {
                    this.xheditor.remove();
                    this.xheditor = null
                }
            } else if (!this.xheditor) {
                var tOptions = /({.*})/.exec($(this).attr("class"));
                if (tOptions) {
                    try {
                        tOptions = eval("(" + tOptions[1] + ")")
                    } catch(ex) {}
                    options = $.extend({},
                    tOptions, options)
                }
                var editor = new $.xheditor(this, options);
                if (editor.init()) {
                    this.xheditor = editor;
                    arrSuccess.push(editor)
                } else editor = null
            }
        });
        if (arrSuccess.length == 0) arrSuccess = false;
        if (arrSuccess.length == 1) arrSuccess = arrSuccess[0];
        return arrSuccess
    };
    var xCount = 0,
    browerVer = $.browser.version,
    isIE = $.browser.msie,
    isMozilla = $.browser.mozilla,
    isSafari = $.browser.safari,
    isOpera = $.browser.opera,
    bShowPanel = false,
    bClickCancel = true,
    _jPanel,
    _jShadow,
    _jCntLine,
    _jPanelButton,
    _jTempIframe,
    editorRoot;
    $("script[src*=xheditor]").each(function() {
        var A = this.src;
        if (A.match(/xheditor[^\/]*\.js/i)) {
            editorRoot = A.replace(/[\?#].*$/, "").replace(/(^|[\/\\])[^\/]*$/, "$1");
            return false
        }
    });
    var specialKeys = {
        27: "esc",
        9: "tab",
        32: "space",
        13: "enter",
        8: "backspace",
        145: "scroll",
        20: "capslock",
        144: "numlock",
        19: "pause",
        45: "insert",
        36: "home",
        46: "del",
        35: "end",
        33: "pageup",
        34: "pagedown",
        37: "left",
        38: "up",
        39: "right",
        40: "down",
        112: "f1",
        113: "f2",
        114: "f3",
        115: "f4",
        116: "f5",
        117: "f6",
        118: "f7",
        119: "f8",
        120: "f9",
        121: "f10",
        122: "f11",
        123: "f12"
    },
    itemColors = ["#FFFFFF", "#CCCCCC", "#C0C0C0", "#999999", "#666666", "#333333", "#000000", "#FFCCCC", "#FF6666", "#FF0000", "#CC0000", "#990000", "#660000", "#330000", "#FFCC99", "#FF9966", "#FF9900", "#FF6600", "#CC6600", "#993300", "#663300", "#FFFF99", "#FFFF66", "#FFCC66", "#FFCC33", "#CC9933", "#996633", "#663333", "#FFFFCC", "#FFFF33", "#FFFF00", "#FFCC00", "#999900", "#666600", "#333300", "#99FF99", "#66FF99", "#33FF33", "#33CC00", "#009900", "#006600", "#003300", "#99FFFF", "#33FFFF", "#66CCCC", "#00CCCC", "#339999", "#336666", "#003333", "#CCFFFF", "#66FFFF", "#33CCFF", "#3366FF", "#3333FF", "#000099", "#000066", "#CCCCFF", "#9999FF", "#6666CC", "#6633FF", "#6600CC", "#333399", "#330099", "#FFCCFF", "#FF99FF", "#CC66CC", "#CC33CC", "#993399", "#663366", "#330033"],
    arrBlocktag = [{
        n: "p",
        t: "\u666e\u901a\u6bb5\u843d"
    },
    {
        n: "h1",
        t: "\u6807\u98981"
    },
    {
        n: "h2",
        t: "\u6807\u98982"
    },
    {
        n: "h3",
        t: "\u6807\u98983"
    },
    {
        n: "h4",
        t: "\u6807\u98984"
    },
    {
        n: "h5",
        t: "\u6807\u98985"
    },
    {
        n: "h6",
        t: "\u6807\u98986"
    },
    {
        n: "pre",
        t: "\u5df2\u7f16\u6392\u683c\u5f0f"
    },
    {
        n: "address",
        t: "\u5730\u5740"
    }],
    arrFontname = [{
        n: "\u5b8b\u4f53",
        c: "SimSun"
    },
    {
        n: "\u4eff\u5b8b\u4f53",
        c: "FangSong_GB2312"
    },
    {
        n: "\u9ed1\u4f53",
        c: "SimHei"
    },
    {
        n: "\u6977\u4f53",
        c: "KaiTi_GB2312"
    },
    {
        n: "\u5fae\u8f6f\u96c5\u9ed1",
        c: "Microsoft YaHei"
    },
    {
        n: "Arial"
    },
    {
        n: "Arial Narrow"
    },
    {
        n: "Arial Black"
    },
    {
        n: "Comic Sans MS"
    },
    {
        n: "Courier New"
    },
    {
        n: "System"
    },
    {
        n: "Times New Roman"
    },
    {
        n: "Tahoma"
    },
    {
        n: "Verdana"
    }],
    arrFontsize = [{
        n: "xx-small",
        wkn: "x-small",
        s: "8pt",
        t: "\u6781\u5c0f"
    },
    {
        n: "x-small",
        wkn: "small",
        s: "10pt",
        t: "\u7279\u5c0f"
    },
    {
        n: "small",
        wkn: "medium",
        s: "12pt",
        t: "\u5c0f"
    },
    {
        n: "medium",
        wkn: "large",
        s: "14pt",
        t: "\u4e2d"
    },
    {
        n: "large",
        wkn: "x-large",
        s: "18pt",
        t: "\u5927"
    },
    {
        n: "x-large",
        wkn: "xx-large",
        s: "24pt",
        t: "\u7279\u5927"
    },
    {
        n: "xx-large",
        wkn: "-webkit-xxx-large",
        s: "36pt",
        t: "\u6781\u5927"
    }],
    menuAlign = [{
        s: "\u5de6\u5bf9\u9f50",
        v: "justifyleft"
    },
    {
        s: "\u5c45\u4e2d",
        v: "justifycenter"
    },
    {
        s: "\u53f3\u5bf9\u9f50",
        v: "justifyright"
    },
    {
        s: "\u4e24\u7aef\u5bf9\u9f50",
        v: "justifyfull"
    }],
    menuList = [{
        s: "\u6570\u5b57\u5217\u8868",
        v: "insertOrderedList"
    },
    {
        s: "\u7b26\u53f7\u5217\u8868",
        v: "insertUnorderedList"
    }],
    htmlPastetext = "<div>\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl+V)\u628a\u5185\u5bb9\u7c98\u8d34\u5230\u65b9\u6846\u91cc\uff0c\u6309 \u786e\u5b9a</div><div><textarea id=\"xhePastetextValue\" wrap=\"soft\" spellcheck=\"false\" style=\"width:300px;height:100px;\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlLink = "<div>\u94fe\u63a5\u5730\u5740: <input type=\"text\" id=\"xheLinkHref\" value=\"http://\" class=\"xheText\" /></div><div>\u6253\u5f00\u65b9\u5f0f: <select id=\"xheLinkTarget\"><option selected=\"selected\" value=\"\">\u9ed8\u8ba4</option><option value=\"_blank\">\u65b0\u7a97\u53e3</option><option value=\"_self\">\u5f53\u524d\u7a97\u53e3</option><option value=\"_parent\">\u7236\u7a97\u53e3</option></select></div><div style=\"display:none\">\u94fe\u63a5\u6587\u5b57: <input type=\"text\" id=\"xheLinkText\" value=\"\" class=\"xheText\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlImg = "<div>\u56fe\u7247\u6587\u4ef6: <input type=\"text\" id=\"xheImgSrc\" value=\"http://\" class=\"xheText\" /></div><div>\u66ff\u6362\u6587\u672c: <input type=\"text\" id=\"xheImgAlt\" /></div><div>\u5bf9\u9f50\u65b9\u5f0f: <select id=\"xheImgAlign\"><option selected=\"selected\" value=\"\">\u9ed8\u8ba4</option><option value=\"left\">\u5de6\u5bf9\u9f50</option><option value=\"right\">\u53f3\u5bf9\u9f50</option><option value=\"top\">\u9876\u7aef</option><option value=\"middle\">\u5c45\u4e2d</option><option value=\"baseline\">\u57fa\u7ebf</option><option value=\"bottom\">\u5e95\u8fb9</option></select></div><div>\u5bbd\u5ea6\u9ad8\u5ea6: <input type=\"text\" id=\"xheImgWidth\" style=\"width:40px;\" /> x <input type=\"text\" id=\"xheImgHeight\" style=\"width:40px;\" /></div><div>\u8fb9\u6846\u5927\u5c0f: <input type=\"text\" id=\"xheImgBorder\" style=\"width:40px;\" /></div><div>\u6c34\u5e73\u95f4\u8ddd: <input type=\"text\" id=\"xheImgHspace\" style=\"width:40px;\" /> \u5782\u76f4\u95f4\u8ddd: <input type=\"text\" id=\"xheImgVspace\" style=\"width:40px;\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlFlash = "<div>\u52a8\u753b\u6587\u4ef6: <input type=\"text\" id=\"xheFlashSrc\" value=\"http://\" class=\"xheText\" /></div><div>\u5bbd\u5ea6\u9ad8\u5ea6: <input type=\"text\" id=\"xheFlashWidth\" style=\"width:40px;\" value=\"480\" /> x <input type=\"text\" id=\"xheFlashHeight\" style=\"width:40px;\" value=\"400\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlMedia = "<div>\u5a92\u4f53\u6587\u4ef6: <input type=\"text\" id=\"xheMediaSrc\" value=\"http://\" class=\"xheText\" /></div><div>\u5bbd\u5ea6\u9ad8\u5ea6: <input type=\"text\" id=\"xheMediaWidth\" style=\"width:40px;\" value=\"480\" /> x <input type=\"text\" id=\"xheMediaHeight\" style=\"width:40px;\" value=\"400\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlTable = "<div>\u884c\u6570\u5217\u6570: <input type=\"text\" id=\"xheTableRows\" style=\"width:40px;\" value=\"3\" /> x <input type=\"text\" id=\"xheTableColumns\" style=\"width:40px;\" value=\"2\" /></div><div>\u6807\u9898\u5355\u5143: <select id=\"xheTableHeaders\"><option selected=\"selected\" value=\"\">\u65e0</option><option value=\"row\">\u7b2c\u4e00\u884c</option><option value=\"col\">\u7b2c\u4e00\u5217</option><option value=\"both\">\u7b2c\u4e00\u884c\u548c\u7b2c\u4e00\u5217</option></select></div><div>\u5bbd\u5ea6\u9ad8\u5ea6: <input type=\"text\" id=\"xheTableWidth\" style=\"width:40px;\" value=\"200\" /> x <input type=\"text\" id=\"xheTableHeight\" style=\"width:40px;\" value=\"\" /></div><div>\u8fb9\u6846\u5927\u5c0f: <input type=\"text\" id=\"xheTableBorder\" style=\"width:40px;\" value=\"1\" /></div><div>\u8868\u683c\u95f4\u8ddd: <input type=\"text\" id=\"xheTableCellSpacing\" style=\"width:40px;\" value=\"1\" /> \u8868\u683c\u586b\u5145: <input type=\"text\" id=\"xheTableCellPadding\" style=\"width:40px;\" value=\"1\" /></div><div>\u5bf9\u9f50\u65b9\u5f0f: <select id=\"xheTableAlign\"><option selected=\"selected\" value=\"\">\u9ed8\u8ba4</option><option value=\"left\">\u5de6\u5bf9\u9f50</option><option value=\"center\">\u5c45\u4e2d</option><option value=\"right\">\u53f3\u5bf9\u9f50</option></select></div><div>\u8868\u683c\u6807\u9898: <input type=\"text\" id=\"xheTableCaption\" /></div><div style=\"text-align:right;\"><input type=\"button\" id=\"xheSave\" value=\"\u786e\u5b9a\" /></div>",
    htmlAbout = "<div style=\"font:12px Arial;width:245px;word-wrap:break-word;word-break:break-all;\"><p><span style=\"font-size:20px;color:#1997DF;\">xhEditor</span><br />v1.0.0 Final (build 100701)</p><p>xhEditor\u662f\u57fa\u4e8ejQuery\u5f00\u53d1\u7684\u8de8\u5e73\u53f0\u8f7b\u91cfXHTML\u7f16\u8f91\u5668\uff0c\u57fa\u4e8e<a href=\"http://www.gnu.org/licenses/lgpl.html\" target=\"_blank\">LGPL</a>\u5f00\u6e90\u534f\u8bae\u53d1\u5e03\u3002</p><p>Copyright \xa9 <a href=\"http://xheditor.com/\" target=\"_blank\">xhEditor.com</a>. All rights reserved.</p></div>",
    itemEmots = {
        "default": {
            name: "\u9ed8\u8ba4",
            width: 28,
            height: 28,
            line: 7,
            list: {
                "1": "\u751f\u6c14",
                "2": "\u5403\u996d",
                "3": "\u7591\u95ee(\u5fae\u7b11)",
                "4": "\u6253\u9488",
                "5": "\u5927\u54ed",
                "6": "\u62f3\u51fb",
                "7": "\u6295\u964d",
                "8": "\u4fef\u5367\u6491",
                "9": "\u7591\u95ee(\u4e0d\u89e3)",
                "10": "\u53d1\u8d22",
                "11": "\u778c\u7761",
                "12": "\u6253\u9171\u6cb9",
                "13": "\u61a8\u7b11",
                "14": "\u5403\u897f\u74dc",
                "15": "\u6c57",
                "16": "\u60ca\u6050",
                "17": "\u4e2d\u6807",
                "18": "\u7ffb\u5899",
                "19": "\u6447\u5934",
                "20": "\u5ff5\u7ecf",
                "21": "\u5bb3\u7f9e",
                "22": "\u7761\u89c9",
                "23": "\u52e4\u594b",
                "24": "\u771f\u68d2",
                "25": "\u5077\u7b11",
                "26": "\u542c\u97f3\u4e50",
                "27": "\u6655"
            }
        }
    },
    arrTools = {
        Cut: {
            t: "\u526a\u5207 (Ctrl+X)"
        },
        Copy: {
            t: "\u590d\u5236 (Ctrl+C)"
        },
        Paste: {
            t: "\u7c98\u8d34 (Ctrl+V)"
        },
        Pastetext: {
            t: "\u7c98\u8d34\u6587\u672c",
            h: isIE ? 0: 1
        },
        Blocktag: {
            t: "\u6bb5\u843d\u6807\u7b7e",
            h: 1
        },
        Fontface: {
            t: "\u5b57\u4f53",
            h: 1
        },
        FontSize: {
            t: "\u5b57\u4f53\u5927\u5c0f",
            h: 1
        },
        Bold: {
            t: "\u52a0\u7c97 (Ctrl+B)",
            s: "Ctrl+B"
        },
        Italic: {
            t: "\u659c\u4f53 (Ctrl+I)",
            s: "Ctrl+I"
        },
        Underline: {
            t: "\u4e0b\u5212\u7ebf (Ctrl+U)",
            s: "Ctrl+U"
        },
        Strikethrough: {
            t: "\u5220\u9664\u7ebf (Ctrl+S)",
            s: "Ctrl+S"
        },
        FontColor: {
            t: "\u5b57\u4f53\u989c\u8272",
            h: 1
        },
        BackColor: {
            t: "\u80cc\u666f\u989c\u8272",
            h: 1
        },
        SelectAll: {
            t: "\u5168\u9009 (Ctrl+A)"
        },
        Removeformat: {
            t: "\u5220\u9664\u6587\u5b57\u683c\u5f0f"
        },
        Align: {
            t: "\u5bf9\u9f50",
            h: 1
        },
        List: {
            t: "\u5217\u8868",
            h: 1
        },
        Outdent: {
            t: "\u51cf\u5c11\u7f29\u8fdb (Shift+Tab)",
            s: "Shift+Tab"
        },
        Indent: {
            t: "\u589e\u52a0\u7f29\u8fdb (Tab)",
            s: "Tab"
        },
        Link: {
            t: "\u8d85\u94fe\u63a5 (Ctrl+K)",
            s: "Ctrl+K",
            h: 1
        },
        Unlink: {
            t: "\u53d6\u6d88\u8d85\u94fe\u63a5"
        },
        Img: {
            t: "\u56fe\u7247",
            h: 1
        },
        Flash: {
            t: "Flash\u52a8\u753b",
            h: 1
        },
        Media: {
            t: "\u591a\u5a92\u4f53\u6587\u4ef6",
            h: 1
        },
        Emot: {
            t: "\u8868\u60c5",
            s: "ctrl+e",
            h: 1
        },
        Table: {
            t: "\u8868\u683c",
            h: 1
        },
        Source: {
            t: "\u6e90\u4ee3\u7801"
        },
        Print: {
            t: "\u6253\u5370 (Ctrl+P)",
            s: "Ctrl+P"
        },
        Fullscreen: {
            t: "\u5168\u5c4f\u7f16\u8f91 (Esc)",
            s: "Esc"
        }
    },
    toolsThemes = {
        zbj: editThemes.zbjall,
        mini: "Bold,Italic,Underline,Strikethrough,Separator,Align,List,Separator,Link,Img",
        simple: "Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Separator,Align,List,Outdent,Indent,Separator,Link,Img,Emot",
        full: "Cut,Copy,Paste,Pastetext,Separator,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,Separator,Align,List,Outdent,Indent,Separator,Link,Unlink,Img,Flash,Media,Emot,Table,Separator,Source,Print,Fullscreen"
    };
    toolsThemes.mfull = toolsThemes.full.replace(/Separator(,Align)/i, "BtnBr$1");
    $.xheditor = function(textarea, options) {
        var defaults = {
            skin: "default",
            tools: "full",
            clickCancelDialog: true,
            linkTag: false,
            internalScript: false,
            inlineScript: false,
            internalStyle: true,
            inlineStyle: true,
            showBlocktag: false,
            forcePtag: true,
            upLinkExt: "zip,rar,txt",
            upImgExt: "jpg,jpeg,gif,png",
            upFlashExt: "swf",
            upMediaExt: "wmv,avi,wma,mp3,mid",
            modalWidth: 350,
            modalHeight: 220,
            modalTitle: true,
            defLinkText: "\u70b9\u51fb\u6253\u5f00\u94fe\u63a5",
            layerShadow: 3,
            emotMark: false,
            upBtnText: "\u4e0a\u4f20",
            wordDeepClean: true,
            hoverExecDelay: 100,
            html5Upload: true,
            upMultiple: 99
        },
        _this = this,
        _text = textarea,
        _jText = $(_text),
        _jForm = _jText.closest("form"),
        _jTools,
        _jArea,
        _win,
        _jWin,
        _doc,
        _jDoc,
        bookmark,
        bInit = false,
        bSource = false,
        bFullscreen = false,
        outerScroll,
        bShowBlocktag = false,
        sLayoutStyle = "",
        ev = null,
        timer,
        bDisableHoverExec = false,
        bQuickHoverExec = false,
        lastPoint = null,
        lastAngle = null,
        editHeight = 0;
        this.settings = $.extend({},
        defaults, options);
        var plugins = _this.settings.plugins,
        strPlugins = [];
        if (plugins) {
            arrTools = $.extend({},
            arrTools, plugins);
            $.each(plugins, 
            function(A) {
                strPlugins.push(A)
            });
            strPlugins = strPlugins.join(",")
        }
        if (_this.settings.tools.match(/^\s*(m?full|simple|mini|zbj)\s*$/i)) {
            var toolsTheme = toolsThemes[$.trim(_this.settings.tools)];
            _this.settings.tools = (_this.settings.tools.match(/m?full/i) && plugins) ? toolsTheme.replace("Table", "Table," + strPlugins) : toolsTheme
        }
        _this.settings.tools = _this.settings.tools.split(",");
        editorRoot = getLocalUrl(editorRoot, "abs");
        var idCSS = "xheCSS_" + _this.settings.skin,
        idContainer = "xhe" + xCount + "_container",
        idTools = "xhe" + xCount + "_Tool",
        idIframeArea = "xhe" + xCount + "_iframearea",
        idIframe = "xhe" + xCount + "_iframe",
        idFixFFCursor = "xhe" + xCount + "_fixffcursor",
        bodyClass = "",
        skinPath = editorRoot + "xheditor_skin/" + _this.settings.skin + "/",
        arrEmots = itemEmots,
        emotPath = getLocalUrl(editorRoot, "rel") + "xheditor_emot/",
        selEmotGroup = "";
        arrEmots = $.extend({},
        arrEmots, _this.settings.emots);
        bShowBlocktag = _this.settings.showBlocktag;
        if (bShowBlocktag) bodyClass += " showBlocktag";
        var arrShortCuts = [];
        this.init = function() {
            if ($("#" + idCSS).length == 0) $("head").append("<link id=\"" + idCSS + "\" rel=\"stylesheet\" type=\"text/css\" href=\"" + skinPath + "ui.css\" />");
            var H = _this.settings.width || _text.style.width || _jText.outerWidth();
            editHeight = _this.settings.height || _text.style.height || _jText.outerHeight();
            if (is(editHeight, "string")) editHeight = editHeight.replace(/[^\d]+/g, "");
            if (H <= 0 || editHeight <= 0) {
                alert("\u5f53\u524dtextarea\u5904\u4e8e\u9690\u85cf\u72b6\u6001\uff0c\u8bf7\u5c06\u4e4b\u663e\u793a\u540e\u518d\u521d\u59cb\u5316xhEditor\uff0c\u6216\u8005\u76f4\u63a5\u8bbe\u7f6etextarea\u7684width\u548cheight\u6837\u5f0f");
                return false
            }
            if (/^[0-9\.]+$/i.test("" + H)) H += "px";
            var G = ["<span class=\"xheGStart\"/>"],
            F,
            D,
            J = /Separator|BtnBr/i;
            $.each(_this.settings.tools, 
            function(B, A) {
                F = arrTools[A];
                if (A.match(J)) G.push("<span class=\"xheGEnd\"/>");
                if (A == "Separator") G.push("<span class=\"xheSeparator\"/>");
                else if (A == "BtnBr") G.push("<br />");
                else {
                    if (F.c) D = F.c;
                    else D = "xheIcon xheBtn" + A;
                    G.push("<span><a href=\"javascript:void(0);\" title=\"" + F.t + "\" name=\"" + A + "\" class=\"xheButton xheEnabled\" tabindex=\"-1\"><span class=\"" + D + "\" unselectable=\"on\" /></a></span>");
                    if (F.s) _this.addShortcuts(F.s, A)
                }
                if (A.match(J)) G.push("<span class=\"xheGStart\"/>")
            });
            G.push("<span class=\"xheGEnd\"/><br />");
            _jText.after($("<input type=\"text\" id=\"" + idFixFFCursor + "\" style=\"position:absolute;display:none;\" /><span id=\"" + idContainer + "\" class=\"xhe_" + _this.settings.skin + "\" style=\"display:none\"><table cellspacing=\"0\" cellpadding=\"0\" class=\"xheLayout\" style=\"width:" + H + ";height:" + editHeight + "px;\"><tbody><tr><td id=\"" + idTools + "\" class=\"xheTool\" unselectable=\"on\" style=\"height:1px;\"></td></tr><tr><td id=\"" + idIframeArea + "\" class=\"xheIframeArea\"><iframe frameborder=\"0\" id=\"" + idIframe + "\" src=\"javascript:;\" style=\"width:100%;\"></iframe></td></tr></tbody></table></span>"));
            _jTools = $("#" + idTools);
            _jArea = $("#" + idIframeArea);
            var E = "<html><head><base /><meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"/><link rel=\"stylesheet\" href=\"" + skinPath + "iframe.css\"/>",
            A = _this.settings.loadCSS;
            if (A) if (is(A, "array")) {
                for (var K in A) E += "<link rel=\"stylesheet\" href=\"" + A[K] + "\"/>"
            } else if (A.match(/\s*<style(\s+[^>]*?)?>[\s\S]+?<\/style>\s*/i)) E += A;
            else E += "<link rel=\"stylesheet\" href=\"" + A + "\"/>";
            E += "</head><body spellcheck=\"false\" dir=\"ltr\" class=\"editMode" + bodyClass + "\"></body></html>";
            _this.win = _win = $("#" + idIframe)[0].contentWindow;
            _jWin = $(_win);
            try {
                this.doc = _doc = _win.document;
                _jDoc = $(_doc);
                _doc.open();
                _doc.write(E);
                _doc.close();
                if (isIE) _doc.body.contentEditable = "true";
                else _doc.designMode = "On"
            } catch(B) {}
            setTimeout(setOpts, 300);
            _this.setSource();
            _win.setInterval = null;
            _jTools.append(G.join("")).bind("mousedown contextmenu", returnFalse).click(function(A) {
                var B = $(A.target).closest("a");
                if (B.is(".xheEnabled")) {
                    ev = A;
                    _this.exec(B.attr("name"))
                }
                return false
            });
            _jTools.find(".xheButton").hover(function(C) {
                var D = $(this),
                F = _this.settings.hoverExecDelay,
                E = lastAngle;
                lastAngle = null;
                if (F == -1 || bDisableHoverExec || !D.is(".xheEnabled")) return false;
                if (E && E > 10) {
                    bDisableHoverExec = true;
                    setTimeout(function() {
                        bDisableHoverExec = false
                    },
                    100);
                    return false
                }
                var A = D.attr("name"),
                B = arrTools[A].h == 1;
                if (!B) {
                    _this.hidePanel();
                    return false
                }
                if (bQuickHoverExec) F = 0;
                if (F >= 0) timer = setTimeout(function() {
                    ev = C;
                    lastPoint = {
                        x: ev.clientX,
                        y: ev.clientY
                    };
                    _this.exec(A)
                },
                F)
            },
            function(A) {
                lastPoint = null;
                if (timer) clearTimeout(timer)
            }).mousemove(function(B) {
                if (lastPoint) {
                    var A = {
                        x: B.clientX - lastPoint.x,
                        y: B.clientY - lastPoint.y
                    };
                    if (Math.abs(A.x) > 1 || Math.abs(A.y) > 1) {
                        if (A.x > 0 && A.y > 0) {
                            var C = Math.round(Math.atan(A.y / A.x) / 0.017453293);
                            if (lastAngle) lastAngle = (lastAngle + C) / 2;
                            else lastAngle = C
                        } else lastAngle = null;
                        lastPoint = {
                            x: B.clientX,
                            y: B.clientY
                        }
                    }
                }
            });
            _jPanel = $("#xhePanel");
            _jShadow = $("#xheShadow");
            _jCntLine = $("#xheCntLine");
            _jTempIframe = $("#xheTempIframe");
            if (_jPanel.length == 0) {
                _jPanel = $("<div id=\"xhePanel\"></div>").mousedown(function(A) {
                    A.stopPropagation()
                });
                _jShadow = $("<div id=\"xheShadow\"></div>");
                _jCntLine = $("<div id=\"xheCntLine\"></div>");
                setTimeout(function() {
                    $(document.body).append(_jPanel).append(_jShadow).append(_jCntLine);
                    if (isIE) $(document.body).append(_jTempIframe = $("<iframe id=\"xheTempIframe\" class=\"xheHideArea\" />"))
                },
                10)
            }
            $(document).mousedown(clickCancelPanel);
            _jDoc.mousedown(clickCancelPanel);
            $("#" + idContainer).show();
            _jArea.css("height", editHeight - _jTools.outerHeight());
            _jText.hide();
            _jText.focus(_this.focus);
            _jForm.submit(saveResult).bind("reset", loadReset);
            var I = $(window);
            I.unload(saveResult).bind("beforeunload", saveResult);
            I.resize(fixFullHeight);
            _jWin.focus(function() {
                if (_this.settings.focus) _this.settings.focus()
            }).blur(function() {
                if (_this.settings.blur) _this.settings.blur()
            });
            if (isSafari) _jWin.click(fixAppleSel);
            _jDoc.keydown(checkShortcuts).keypress(forcePtag).bind("mousedown click", 
            function(A) {
                _jText.trigger(A.type)
            });
            $("body", _jDoc).bind("paste", cleanWordPaste);
            var C = _this.settings.shortcuts;
            if (C) $.each(C, 
            function(B, A) {
                _this.addShortcuts(B, A)
            });
            xCount++;
            bInit = true;
            if (_this.settings.fullscreen) _this.toggleFullscreen();
            else if (_this.settings.sourceMode) setTimeout(_this.toggleSource, 20);
            return true
        };
        this.remove = function() {
            _this.hidePanel();
            saveResult();
            _jText.unbind("focus", _this.focus);
            _jForm.unbind("submit", saveResult).unbind("reset", loadReset);
            var A = $(window);
            A.unbind("unload", saveResult).unbind("beforeunload", saveResult);
            A.unbind("resize", fixFullHeight);
            $("#" + idContainer).remove();
            $("#" + idFixFFCursor).remove();
            _jText.show();
            bInit = false
        };
        this.saveBookmark = function() {
            if (!bSource) bookmark = _this.getRng()
        };
        this.loadBookmark = function() {
            if (bSource || !bookmark) return;
            _this.focus();
            if (isIE) bookmark.select();
            else {
                var A = _this.getSel();
                A.removeAllRanges();
                A.addRange(bookmark)
            }
            bookmark = null
        };
        this.focus = function() {
            if (!bSource) _jWin.focus();
            else $("#sourceCode", _doc).focus();
            return false
        };
        this.setCursorFirst = function(E) {
            _this.focus();
            _win.scrollTo(0, 0);
            var D = _this.getRng(),
            B = _doc.body,
            C = B,
            A;
            if (E && C.firstChild && (A = C.firstChild.tagName) && A.match(/^p|div|h[1-6]$/i)) C = B.firstChild;
            isIE ? D.moveToElementText(C) : D.setStart(C, 0);
            D.collapse(true);
            if (isIE) D.select();
            else {
                var F = _this.getSel();
                F.removeAllRanges();
                F.addRange(D)
            }
        };
        this.getSel = function() {
            return _win.getSelection ? _win.getSelection() : _doc.selection
        };
        this.getRng = function() {
            var C = _this.getSel(),
            B;
            try {
                B = C.rangeCount > 0 ? C.getRangeAt(0) : (C.createRange ? C.createRange() : _doc.createRange())
            } catch(A) {}
            if (!B) B = isIE ? _doc.body.createTextRange() : _doc.createRange();
            return B
        };
        this.getParent = function(A) {
            var C = _this.getRng(),
            B;
            if (!isIE) {
                B = C.commonAncestorContainer;
                if (!C.collapsed) if (C.startContainer == C.endContainer && C.startOffset - C.endOffset < 2 && C.startContainer.hasChildNodes()) B = C.startContainer.childNodes[C.startOffset]
            } else B = C.item ? C.item(0) : C.parentElement();
            A = A ? A: "*";
            B = $(B);
            if (!B.is(A)) B = $(B).closest(A);
            return B
        };
        this.getSelect = function(F) {
            var G = _this.getSel(),
            C = _this.getRng(),
            E = true;
            if (!C || C.item) E = false;
            else E = !G || C.boundingWidth == 0 || C.collapsed;
            if (F == "text") return E ? "": (C.text || (G.toString ? G.toString() : ""));
            var B;
            if (C.cloneContents) {
                var D = $("<div></div>"),
                A;
                A = C.cloneContents();
                if (A) D.append(A);
                B = D.html()
            } else if (is(C.item)) B = C.item(0).outerHTML;
            else if (is(C.htmlText)) B = C.htmlText;
            else B = C.toString();
            if (E) B = "";
            B = _this.processHTML(B, "read");
            B = _this.cleanHTML(B);
            B = _this.formatXHTML(B);
            return B
        };
        this.pasteHTML = function(D, A) {
            if (bSource) return false;
            _this.focus();
            D = _this.processHTML(D, "write");
            var G = _this.getSel(),
            C = _this.getRng();
            if (A != undefined) {
                if (C.item) {
                    var B = C.item(0);
                    C = _doc.body.createTextRange();
                    C.moveToElementText(B);
                    C.select()
                }
                C.collapse(A)
            }
            if (C.insertNode) {
                C.deleteContents();
                var F = C.createContextualFragment(D),
                E = F.lastChild;
                C.insertNode(F);
                C.setEndAfter(E);
                C.collapse(false);
                G.removeAllRanges();
                G.addRange(C)
            } else {
                if (G.type.toLowerCase() == "control") {
                    G.clear();
                    C = _this.getRng()
                }
                C.pasteHTML(D)
            }
        };
        this.pasteText = function(A, B) {
            if (!A) A = "";
            A = _this.domEncode(A);
            A = A.replace(/\r?\n/g, "<br />");
            _this.pasteHTML(A, B)
        };
        this.appendHTML = function(A) {
            if (bSource) return false;
            _this.focus();
            A = _this.processHTML(A, "write");
            $(_doc.body).append(A)
        };
        this.domEncode = function(A) {
            return A.replace(/[<>]/g, 
            function(A) {
                return {
                    "<": "&lt;",
                    ">": "&gt;"
                } [A]
            })
        };
        this.setSource = function(A) {
            bookmark = null;
            if (typeof A != "string" && A != "") A = _text.value;
            if (bSource) $("#sourceCode", _doc).val(A);
            else {
                if (_this.settings.beforeSetSource) A = _this.settings.beforeSetSource(A);
                A = _this.cleanHTML(A);
                A = _this.formatXHTML(A);
                A = _this.cleanWord(A);
                _doc.body.innerHTML = _this.processHTML(A, "write")
            }
        };
        this.processHTML = function(F, J) {
            var D = " class=\"Apple-style-span\"";
            if (J == "write") {
                function G(D, C, B, A) {
                    A = A.split(",");
                    if (!A[1]) {
                        A[1] = A[0];
                        A[0] = ""
                    }
                    if (A[0] == "default") A[0] = "";
                    return D.replace(/\s+src\s*=\s*(["']?).*?\1(\s|$|\/|>)/i, "$2").replace(C, " src=\"" + emotPath + (A[0] ? A[0] : "default") + "/" + A[1] + ".gif\"" + (_this.settings.emotMark ? " emot=\"" + (A[0] ? A[0] + ",": "") + A[1] + "\" alt=\"" + A[1] + "\"": ""))
                }
                F = F.replace(/<img(?:\s+[^>]*?)?(\s+emot\s*=\s*(["']?)\s*(.*?)\s*\2)(?:\s+[^>]*?)?\/?>/ig, G);
                function C(F, C, E, D, B, A) {
                    return F.replace(E, E + " _xhe_" + D + "=\"" + A + "\"")
                }
                F = F.replace(/<(\w+(?:\:\w+)?)(?:\s+[^>]*?)?(\s+(src|href)\s*=\s*(["']?)\s*(.*?)\s*\4)(?:\s+[^>]*?)?\/?>/ig, C);
                F = F.replace(/<(\/?)del(\s+[^>]*?)?>/ig, "<$1strike$2>");
                if (isMozilla) {
                    F = F.replace(/<(\/?)strong(\s+[^>]*?)?>/ig, "<$1b$2>");
                    F = F.replace(/<(\/?)em(\s+[^>]*?)?>/ig, "<$1i$2>")
                } else if (isSafari) {
                    F = F.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig, 
                    function(F, D, E, C) {
                        var A,
                        B;
                        for (var G = 0; G < arrFontsize.length; G++) {
                            A = arrFontsize[G];
                            if (E == A.n) {
                                B = A.wkn;
                                break
                            }
                        }
                        return D + "font-size:" + B + C
                    });
                    F = F.replace(/<strong(\s+[^>]*?)?>/ig, "<span" + D + " style=\"font-weight: bold;\"$1>");
                    F = F.replace(/<em(\s+[^>]*?)?>/ig, "<span" + D + " style=\"font-style: italic;\"$1>");
                    F = F.replace(/<u(\s+[^>]*?)?>/ig, "<span" + D + " style=\"text-decoration: underline;\"$1>");
                    F = F.replace(/<strike(\s+[^>]*?)?>/ig, "<span" + D + " style=\"text-decoration: line-through;\"$1>");
                    F = F.replace(/<\/(strong|em|u|strike)>/ig, "</span>");
                    F = F.replace(/<span((?:\s+[^>]*?)?\s+style="([^"]*;)*\s*(font-family|font-size|color|background-color)\s*:\s*[^;"]+\s*;?"[^>]*)>/ig, "<span" + D + "$1>")
                } else if (isIE) {
                    F = F.replace(/&apos;/ig, "&#39;");
                    F = F.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/ig, "")
                }
                F = F.replace(/<a(\s+[^>]*?)?\/>/, "<a$1></a>");
                if (!isSafari) {
                    function B(L, E, J, I) {
                        var K = "",
                        A,
                        C,
                        B,
                        D;
                        A = J.match(/font-family\s*:\s*([^;"]+)/i);
                        if (A) K += " face=\"" + A[1] + "\"";
                        C = J.match(/font-size\s*:\s*([^;"]+)/i);
                        if (C) {
                            C = C[1].toLowerCase();
                            for (var G = 0; G < arrFontsize.length; G++) if (C == arrFontsize[G].n || C == arrFontsize[G].s) {
                                B = G + 1;
                                break
                            }
                            if (B) {
                                K += " size=\"" + B + "\"";
                                J = J.replace(/(^|;)(\s*font-size\s*:\s*[^;"]+;?)+/ig, "$1")
                            }
                        }
                        D = J.match(/(?:^|[\s;])color\s*:\s*([^;"]+)/i);
                        if (D) {
                            var F;
                            if (F = D[1].match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)) {
                                D[1] = "#";
                                for (var H = 1; H <= 3; H++) D[1] += (F[H] - 0).toString(16)
                            }
                            D[1] = D[1].replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i, "#$1$1$2$2$3$3");
                            K += " color=\"" + D[1] + "\""
                        }
                        J = J.replace(/(^|;)(\s*(font-family|color)\s*:\s*[^;"]+;?)+/ig, "$1");
                        if (K != "") {
                            if (J) K += " style=\"" + J + "\"";
                            return "<font" + K + ">" + I + "</font>"
                        } else return L
                    }
                    F = F.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig, B);
                    F = F.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig, B);
                    F = F.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig, B)
                }
            } else {
                var A = _this.settings.localUrl;
                function H(E, D, C, B) {
                    if (A) B = getLocalUrl(B, A);
                    return E.replace(new RegExp("\\s+" + D + "\\s*=\\s*([\"']?).*?\\1(\\s|/?>)", "ig"), " " + D + "=\"" + B.replace(/\$/g, "$$$$") + "\"$2")
                }
                F = F.replace(/<(?:\w+(?:\:\w+)?)(?:\s+[^>]*?)?\s+_xhe_(src|href)\s*=\s*(["']?)\s*(.*?)\s*\2(?:\s+[^>]*?)?\/?>/ig, H);
                if (isSafari) {
                    F = F.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig, 
                    function(F, D, E, C) {
                        var A,
                        B;
                        for (var G = 0; G < arrFontsize.length; G++) {
                            A = arrFontsize[G];
                            if (E == A.wkn) {
                                B = A.n;
                                break
                            }
                        }
                        return D + "font-size:" + B + C
                    });
                    var I = [{
                        r: /font-weight:\sbold/ig,
                        t: "strong"
                    },
                    {
                        r: /font-style:\sitalic/ig,
                        t: "em"
                    },
                    {
                        r: /text-decoration:\sunderline/ig,
                        t: "u"
                    },
                    {
                        r: /text-decoration:\sline-through/ig,
                        t: "strike"
                    }];
                    function E(G, C, E, D, A) {
                        var F = E + D,
                        B = "";
                        for (var H = 0; H < I.length; H++) if (F.match(I[H].r)) {
                            B = I[H].t;
                            break
                        }
                        if (B) return "<" + B + ">" + A + "</" + B + ">";
                        else return G
                    }
                    F = F.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig, E);
                    F = F.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig, E);
                    F = F.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig, E)
                }
                F = F.replace(/(<\w+(?:\s+[^>]*?)?)\s+(?:_xhe_|_moz_|_webkit_)[^=]+?\s*=\s*(["']?).*?\2(\s|\/?>)/ig, "$1$3");
                F = F.replace(/(<\w+[^>]*?)\s+class\s*=\s*(["']?)\s*(?:apple|webkit)\-.+?\s*\2(\s|\/?>)/ig, "$1$3");
                F = F.replace(/<img(\s+[^>]+?)\/?>/ig, 
                function(B, A) {
                    if (!A.match(/\s+alt\s*(["']?).*?\1(\s|$)/i)) A += " alt=\"\"";
                    return "<img" + A + " />"
                })
            }
            return F
        };
        this.getSource = function(A) {
            var B,
            C = _this.settings.beforeGetSource;
            if (bSource) {
                B = $("#sourceCode", _doc).val();
                if (!C) B = B.replace(/(\t*\r?\n\t*)+/g, "")
            } else {
                B = _this.processHTML(_doc.body.innerHTML, "read");
                B = B.replace(/^\s*(?:<(p|div)(?:\s+[^>]*?)?>)?\s*(<br(?:\s+[^>]*?)?>)*\s*(?:<\/\1>)?\s*$/i, "");
                B = _this.cleanHTML(B);
                B = _this.formatXHTML(B, A);
                B = _this.cleanWord(B);
                if (C) B = C(B)
            }
            _text.value = B;
            return B
        };
        this.cleanWord = function(A) {
            if (A.match(/mso(-|normal)/i)) {
                var B = _this.settings.wordDeepClean;
                A = A.replace(/(<link(?:\s+[^>]*?)?)\s+href\s*=\s*(["']?)\s*file:\/\/.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig, "");
                A = A.replace(/<!--[\s\S]*?-->|<!(--)?\[[\s\S]+?\](--)?>|<style(\s+[^>]*?)?>[\s\S]*?<\/style>/ig, "");
                A = A.replace(/<\/?\w+:[^>]*>/ig, "");
                if (B) A = A.replace(/<\/?(span|a|img)(\s+[^>]*?)?>/ig, "");
                A = A.replace(/(<\w+(?:\s+[^>]*?)?)\s+class\s*=\s*(["']?)\s*mso.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig, "$1$3");
                A = A.replace(/(<\w+(?:\s+[^>]*?)?)\s+lang\s*=\s*(["']?)\s*.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig, "$1$3");
                A = A.replace(/(<\w+(?:\s+[^>]*?)?)\s+align\s*=\s*(["']?)\s*left\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig, "$1$3");
                A = A.replace(/<\w+(?:\s+[^>]*?)?(\s+style\s*=\s*(["']?)\s*([\s\S]*?)\s*\2)(?:\s+[^>]*?)?\s*\/?>/ig, 
                function(E, D, A, C) {
                    C = $.trim(C.replace(/\s*(mso-[^:]+:.+?|margin\s*:\s*0cm 0cm 0pt\s*|(text-align|font-variant|line-height)\s*:\s*.+?)(;|$)\s*/ig, ""));
                    return E.replace(D, B ? "": C ? " style=\"" + C + "\"": "")
                })
            }
            return A
        };
        this.cleanHTML = function(A) {
            A = A.replace(/<!?\/?(DOCTYPE|html|body|meta)(\s+[^>]*?)?>/ig, "");
            var B;
            A = A.replace(/<head(?:\s+[^>]*?)?>([\s\S]*?)<\/head>/i, 
            function(C, A) {
                B = A.match(/<(script|style)(\s+[^>]*?)?>[\s\S]*?<\/\1>/ig);
                return ""
            });
            if (B) A = B.join("") + A;
            A = A.replace(/<\??xml(:\w+)?(\s+[^>]*?)?>([\s\S]*?<\/xml>)?/ig, "");
            if (!_this.settings.linkTag) A = A.replace(/<link(\s+[^>]*?)?>/ig, "");
            if (!_this.settings.internalScript) A = A.replace(/<script(\s+[^>]*?)?>[\s\S]*?<\/script>/ig, "");
            if (!_this.settings.inlineScript) A = A.replace(/(<\w+)(\s+[^>]*?)?\s+on(?:click|dblclick|mousedown|mouseup|mousemove|mouseover|mouseout|mouseenter|mouseleave|keydown|keypress|keyup|change|select|submit|reset|blur|focus|load|unload)\s*=\s*(["']?).*?\3((?:\s+[^>]*?)?\/?>)/ig, "$1$2$4");
            if (!_this.settings.internalStyle) A = A.replace(/<style(\s+[^>]*?)?>[\s\S]*?<\/style>/ig, "");
            if (!_this.settings.inlineStyle) A = A.replace(/(<\w+)(\s+[^>]*?)?\s+(style|class)\s*=\s*(["']?).*?\4((?:\s+[^>]*?)?\/?>)/ig, "$1$2$5");
            A = A.replace(/<\/(strong|b|u|strike|em|i)>((?:\s|<br\/?>|&nbsp;)*?)<\1(\s+[^>]*?)?>/ig, "$2");
            return A
        };
        this.formatXHTML = function(O, L) {
            var Z = F("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"),
            P = F("address,applet,blockquote,button,center,dd,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul"),
            Y = F("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"),
            T = F("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"),
            N = F("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),
            S = F("script,style"),
            R = {
                "b": "strong",
                "i": "em",
                "s": "del",
                "strike": "del"
            },
            J = /^<\??(\w+(?:\:\w+)?)((?:\s+[\w-\:]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
            A = /^<\/(\w+(?:\:\w+)?)[^>]*>/,
            Q = /([\w-(?:\:\w+)?]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g,
            E = 0,
            X = [],
            C = O,
            G = Array(),
            U = -1,
            B = "body",
            D;
            X.last = function() {
                return this[this.length - 1]
            };
            while (C.length > 0) if (!X.last() || !S[X.last()]) {
                E = 0;
                if (C.substring(0, 4) == "<!--") {
                    E = C.indexOf("-->");
                    if (E != -1) {
                        E += 3;
                        V(C.substring(0, E))
                    }
                } else if (C.substring(0, 2) == "</") {
                    match = C.match(A);
                    if (match) {
                        H(match[1]);
                        E = match[0].length
                    }
                } else if (C.charAt(0) == "<") {
                    match = C.match(J);
                    if (match) {
                        W(match[1], match[2], match[3]);
                        E = match[0].length
                    }
                }
                if (E == 0) {
                    E = C.indexOf("<");
                    if (E == 0) E = 1;
                    else if (E < 0) E = C.length;
                    V(_this.domEncode(C.substring(0, E)))
                }
                C = C.substring(E)
            } else {
                C = C.replace(/^([\s\S]*?)<\/(style|script)>/i, 
                function(C, B, A) {
                    V(B);
                    return ""
                });
                H(X.last())
            }
            H();
            O = G.join("");
            G = null;
            function F(A) {
                var C = {},
                B = A.split(",");
                for (var D = 0; D < B.length; D++) C[B[D]] = true;
                return C
            }
            function M(B) {
                if (B) {
                    B = B.toLowerCase();
                    var A = R[B];
                    if (A) B = A
                } else B = "";
                return B
            }
            function W(B, C, A) {
                B = M(B);
                if (P[B]) while (X.last() && Y[X.last()]) H(X.last());
                if (T[B] && X.last() == B) H(B);
                A = Z[B] || !!A;
                if (!A) X.push(B);
                var D = Array();
                D.push("<" + B);
                C.replace(Q, 
                function(C, A) {
                    A = A.toLowerCase();
                    var B = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : N[A] ? A: "";
                    D.push(" " + A + "=\"" + B + "\"")
                });
                D.push((A ? " /": "") + ">");
                V(D.join(""), B, true)
            }
            function H(A) {
                if (!A) var C = 0;
                else {
                    A = M(A);
                    for (C = X.length - 1; C >= 0; C--) if (X[C] == A) break
                }
                if (C >= 0) {
                    for (var B = X.length - 1; B >= C; B--) V("</" + X[B] + ">", X[B]);
                    X.length = C
                }
            }
            function V(H, F, E) {
                if (L == true) {
                    H = H.replace(/(\t*\r?\n\t*)+/g, "");
                    if (H.match(/^\s*$/)) return;
                    var A = P[F],
                    C = A ? F: "";
                    if (A) {
                        if (E) U++;
                        if (B == "") U--
                    } else if (B) U++;
                    if (C != B || A) K();
                    G.push(H);
                    if (F == "br") K();
                    if (A && (Z[F] || !E)) U--;
                    B = A ? F: "";
                    D = E
                } else G.push(H)
            }
            function K() {
                G.push("\r\n");
                if (U > 0) {
                    var A = U;
                    while (A--) G.push("\t")
                }
            }
            function I(I, G, F, B) {
                var H = "",
                A,
                D,
                E,
                C;
                A = F.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);
                if (A) H += "font-family:" + A[1] + ";";
                D = F.match(/ size\s*=\s*"\s*(\d+)\s*"/i);
                if (D) H += "font-size:" + arrFontsize[(D[1] > 7 ? 7: (D[1] < 1 ? 1: D[1])) - 1].n + ";";
                E = F.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);
                if (E) H += "color:" + E[1] + ";";
                C = F.match(/ style\s*=\s*"\s*([^"]+)\s*"/i);
                if (C) H += C[1];
                if (H) B = "<span style=\"" + H + "\">" + B + "</span>";
                return B
            }
            O = O.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig, I);
            O = O.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig, I);
            O = O.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig, I);
            O = O.replace(/^(\s*\r?\n)+|(\s*\r?\n)+$/g, "");
            O = O.replace(/(\t*\r?\n)+/g, "\r\n");
            return O
        };
        this.toggleShowBlocktag = function(B) {
            if (bShowBlocktag === B) return;
            bShowBlocktag = !bShowBlocktag;
            var A = $(_doc.body);
            if (bShowBlocktag) {
                bodyClass += " showBlocktag";
                A.addClass("showBlocktag")
            } else {
                bodyClass = bodyClass.replace(" showBlocktag", "");
                A.removeClass("showBlocktag")
            }
        };
        this.toggleSource = function(F) {
            if (bSource === F) return;
            _jTools.find("[name=Source]").toggleClass("xheEnabled").toggleClass("xheActive");
            var C = _doc.body,
            H = $(C),
            E,
            B,
            G = "_xhe_cursor" + new Date().getTime(),
            A = 0;
            if (!bSource) {
                _this.pasteHTML(G, true);
                E = _this.getSource(true);
                A = E.indexOf(G);
                if (!isOpera) A = E.substring(0, A).replace(/\r/g, "").length;
                E = E.replace(G, "");
                if (isIE) C.contentEditable = "false";
                else _doc.designMode = "Off";
                H.attr("scroll", "no").attr("class", "sourceMode").html("<textarea id=\"sourceCode\" wrap=\"soft\" spellcheck=\"false\" height=\"100%\" />");
                B = $("#sourceCode", H).blur(_this.getSource)[0]
            } else {
                E = _this.getSource();
                H.find("#sourceCode").remove();
                H.removeAttr("scroll").attr("class", "editMode" + bodyClass);
                if (isIE) C.contentEditable = "true";
                else _doc.designMode = "On";
                if (isMozilla) {
                    _this._exec("inserthtml", "-");
                    $("#" + idFixFFCursor).show().focus().hide()
                }
            }
            bSource = !bSource;
            _this.setSource(E);
            if (bSource) {
                _this.focus();
                if (B.setSelectionRange) B.setSelectionRange(A, A);
                else {
                    var D = B.createTextRange();
                    D.move("character", A);
                    D.select()
                }
            } else _this.setCursorFirst(true);
            _jTools.find("[name=Source]").toggleClass("xheEnabled");
            _jTools.find(".xheButton").not("[name=Source],[name=Fullscreen]").toggleClass("xheEnabled");
            setTimeout(setOpts, 300)
        };
        this.toggleFullscreen = function(B) {
            if (bFullscreen === B) return;
            var C = $("#" + idContainer).find(".xheLayout"),
            A = $("#" + idContainer);
            if (bFullscreen) {
                C.attr("style", sLayoutStyle);
                _jArea.height(editHeight - _jTools.outerHeight());
                setTimeout(function() {
                    $(window).scrollTop(outerScroll)
                },
                10)
            } else {
                outerScroll = $(window).scrollTop();
                sLayoutStyle = C.attr("style");
                C.removeAttr("style");
                _jArea.height("100%");
                setTimeout(fixFullHeight, 100)
            }
            if (isMozilla) {
                $("#" + idFixFFCursor).show().focus().hide();
                setTimeout(_this.focus, 1)
            }
            bFullscreen = !bFullscreen;
            A.toggleClass("xhe_Fullscreen");
            $("html").toggleClass("xhe_Fullfix");
            _jTools.find("[name=Fullscreen]").toggleClass("xheActive");
            setTimeout(setOpts, 300)
        };
        this.showMenu = function(C, D) {
            var B = $("<div class=\"xheMenu\"></div>"),
            A = [];
            $.each(C, 
            function(C, B) {
                A.push("<a href=\"javascript:void(0);\" title=\"" + (B.t ? B.t: B.s) + "\" v=\"" + B.v + "\">" + B.s + "</a>")
            });
            B.append(A.join(""));
            B.click(function(A) {
                D($(A.target).closest("a").attr("v"));
                _this.hidePanel();
                return false
            }).mousedown(returnFalse);
            _this.showPanel(B)
        };
        this.showColor = function(C) {
            var D = $("<div class=\"xheColor\"></div>"),
            B = [],
            A = 0;
            $.each(itemColors, 
            function(D, C) {
                if (A % 7 == 0) B.push((A > 0 ? "</div>": "") + "<div>");
                B.push("<a href=\"javascript:void(0);\" xhev=\"" + C + "\" title=\"" + C + "\" style=\"background:" + C + "\"></a>");
                A++
            });
            B.push("</div>");
            D.append(B.join(""));
            D.click(function(A) {
                A = A.target;
                if (!$.nodeName(A, "A")) return;
                C($(A).attr("xhev"));
                _this.hidePanel();
                return false
            }).mousedown(returnFalse);
            _this.showPanel(D)
        };
        this.showPastetext = function() {
            var B = $(htmlPastetext),
            C = $("#xhePastetextValue", B),
            A = $("#xheSave", B);
            A.click(function() {
                _this.loadBookmark();
                var A = C.val();
                if (A) _this.pasteText(A);
                _this.hidePanel();
                return false
            });
            _this.showDialog(B)
        };
        this.showLink = function() {
            var C = $(htmlLink),
            E = _this.getParent("a"),
            F = $("#xheLinkText", C),
            G = $("#xheLinkHref", C),
            A = $("#xheLinkTarget", C),
            D = $("#xheSave", C),
            B = _this.getSelect();
            if (E.length == 1) {
                G.val(xheAttr(E, "href"));
                A.attr("value", E.attr("target"))
            } else if (B == "") F.val(_this.settings.defLinkText).closest("div").show();
            if (_this.settings.upLinkUrl) _this.uploadInit(G, _this.settings.upLinkUrl, _this.settings.upLinkExt);
            D.click(function() {
                var L = G.val();
                _this.loadBookmark();
                if (L == "" || E.length == 0) _this._exec("unlink");
                if (L != "" && L != "http://") {
                    var K = L.split(" "),
                    I = A.val(),
                    D = F.val();
                    if (K.length > 1) {
                        _this._exec("unlink");
                        B = _this.getSelect();
                        var H = "<a href=\"xhe_tmpurl\"",
                        J,
                        C = [];
                        if (I != "") H += " target=\"" + I + "\"";
                        H += ">xhe_tmptext</a>";
                        D = (B != "" ? B: (D ? D: L));
                        for (var M in K) {
                            L = K[M];
                            if (L != "") {
                                L = L.split("||");
                                J = H;
                                J = J.replace("xhe_tmpurl", L[0]);
                                J = J.replace("xhe_tmptext", L[1] ? L[1] : D);
                                C.push(J)
                            }
                        }
                        _this.pasteHTML(C.join("&nbsp;"))
                    } else {
                        L = K[0].split("||");
                        if (!D) D = L[0];
                        D = L[1] ? L[1] : (B != "") ? "": D ? D: L[0];
                        if (E.length == 0) {
                            if (D) _this.pasteHTML("<a href=\"#xhe_tmpurl\">" + D + "</a>");
                            else _this._exec("createlink", "#xhe_tmpurl");
                            E = $("a[href$=\"#xhe_tmpurl\"]", _doc)
                        }
                        xheAttr(E, "href", L[0]);
                        if (I != "") E.attr("target", I);
                        else E.removeAttr("target");
                        if (D && !isSafari) E.text(D)
                    }
                }
                _this.hidePanel();
                return false
            });
            _this.showDialog(C)
        };
        this.showImg = function() {
            var G = $(htmlImg),
            K = _this.getParent("img"),
            A = $("#xheImgSrc", G),
            I = $("#xheImgAlt", G),
            L = $("#xheImgAlign", G),
            H = $("#xheImgWidth", G),
            D = $("#xheImgHeight", G),
            J = $("#xheImgBorder", G),
            E = $("#xheImgVspace", G),
            F = $("#xheImgHspace", G),
            B = $("#xheSave", G);
            if (K.length == 1) {
                A.val(xheAttr(K, "src"));
                I.val(K.attr("alt"));
                L.val(K.attr("align"));
                H.val(K.attr("width"));
                D.val(K.attr("height"));
                J.val(K.attr("border"));
                var M = K.attr("vspace"),
                C = K.attr("hspace");
                E.val(M <= 0 ? "": M);
                F.val(C <= 0 ? "": C)
            }
            if (_this.settings.upImgUrl) _this.uploadInit(A, _this.settings.upImgUrl, _this.settings.upImgExt);
            B.click(function() {
                _this.loadBookmark();
                var O = A.val();
                if (O != "" && O != "http://") {
                    var G = O.split(" "),
                    B = I.val(),
                    S = L.val(),
                    M = H.val(),
                    V = D.val(),
                    R = J.val(),
                    U = E.val(),
                    T = F.val();
                    if (G.length > 1) {
                        var Q = "<img src=\"xhe_tmpurl\"",
                        W,
                        N = [];
                        if (B != "") Q += " alt=\"" + B + "\"";
                        if (S != "") Q += " align=\"" + S + "\"";
                        if (M != "") Q += " width=\"" + M + "\"";
                        if (V != "") Q += " height=\"" + V + "\"";
                        if (R != "") Q += " border=\"" + R + "\"";
                        if (U != "") Q += " vspace=\"" + U + "\"";
                        if (T != "") Q += " hspace=\"" + T + "\"";
                        Q += " />";
                        for (var P in G) {
                            O = G[P];
                            if (O != "") {
                                O = O.split("||");
                                W = Q;
                                W = W.replace("xhe_tmpurl", O[0]);
                                if (O[1]) W = "<a href=\"" + O[1] + "\" target=\"_blank\">" + W + "</a>";
                                N.push(W)
                            }
                        }
                        _this.pasteHTML(N.join("&nbsp;"))
                    } else if (G.length == 1) {
                        O = G[0];
                        if (O != "") {
                            O = O.split("||");
                            if (K.length == 0) {
                                _this.pasteHTML("<img src=\"" + O[0] + "#xhe_tmpurl\" />");
                                K = $("img[src$=\"#xhe_tmpurl\"]", _doc)
                            }
                            xheAttr(K, "src", O[0]);
                            if (B != "") K.attr("alt", B);
                            if (S != "") K.attr("align", S);
                            else K.removeAttr("align");
                            if (M != "") K.attr("width", M);
                            else K.removeAttr("width");
                            if (V != "") K.attr("height", V);
                            else K.removeAttr("height");
                            if (R != "") K.attr("border", R);
                            else K.removeAttr("border");
                            if (U != "") K.attr("vspace", U);
                            else K.removeAttr("vspace");
                            if (T != "") K.attr("hspace", T);
                            else K.removeAttr("hspace");
                            if (O[1]) {
                                var C = K.parent("a");
                                if (C.length == 0) {
                                    K.wrap("<a></a>");
                                    C = K.parent("a")
                                }
                                xheAttr(C, "href", O[1]);
                                C.attr("target", "_blank")
                            }
                        }
                    }
                } else if (K.length == 1) K.remove();
                _this.hidePanel();
                return false
            });
            _this.showDialog(G)
        };
        this.showEmbed = function(J, D, L, M, H, F, I) {
            var E = $(D),
            K = _this.getParent("embed[type=\"" + L + "\"],embed[classid=\"" + M + "\"]"),
            A = $("#xhe" + J + "Src", E),
            G = $("#xhe" + J + "Width", E),
            C = $("#xhe" + J + "Height", E),
            B = $("#xheSave", E);
            if (F) _this.uploadInit(A, F, I);
            _this.showDialog(E);
            if (K.length == 1) {
                A.val(xheAttr(K, "src"));
                G.val(K.attr("width"));
                C.val(K.attr("height"))
            }
            B.click(function() {
                _this.loadBookmark();
                var P = A.val();
                if (P != "" && P != "http://") {
                    var D = G.val(),
                    O = C.val(),
                    F = /^[0-9]+$/;
                    if (!F.test(D)) D = 412;
                    if (!F.test(O)) O = 300;
                    var B = "<embed type=\"" + L + "\" classid=\"" + M + "\" src=\"xhe_tmpurl\"" + H,
                    N = P.split(" ");
                    if (N.length > 1) {
                        var E = B + "",
                        J,
                        I = [];
                        E += " width=\"xhe_width\" height=\"xhe_height\" />";
                        for (var Q in N) {
                            P = N[Q].split("||");
                            J = E;
                            J = J.replace("xhe_tmpurl", P[0]);
                            J = J.replace("xhe_width", P[1] ? P[1] : D);
                            J = J.replace("xhe_height", P[2] ? P[2] : O);
                            if (P != "") I.push(J)
                        }
                        _this.pasteHTML(I.join("&nbsp;"))
                    } else if (N.length == 1) {
                        P = N[0].split("||");
                        if (K.length == 0) {
                            _this.pasteHTML(B.replace("xhe_tmpurl", P[0] + "#xhe_tmpurl") + " />");
                            K = $("embed[src$=\"#xhe_tmpurl\"]", _doc)
                        }
                        xheAttr(K, "src", P[0]);
                        K.attr("width", P[1] ? P[1] : D);
                        K.attr("height", P[2] ? P[2] : O)
                    }
                } else if (K.length == 1) K.remove();
                _this.hidePanel();
                return false
            })
        };
        this.showEmot = function(P) {
            var D = $("<div class=\"xheEmot\"></div>");
            P = P ? P: (selEmotGroup ? selEmotGroup: "default");
            var E = arrEmots[P],
            R = emotPath + P + "/",
            F = 0,
            C = [],
            G = "",
            A = E.width,
            M = E.height,
            H = E.line,
            B = E.count,
            I = E.list;
            if (B) {
                for (var K = 1; K <= B; K++) {
                    F++;
                    C.push("<a href=\"javascript:void(0);\" style=\"background-image:url(" + R + K + ".gif);\" emot=\"" + P + "," + K + "\" xhev=\"\">&nbsp;</a>");
                    if (F % H == 0) C.push("<br />")
                }
            } else $.each(I, 
            function(A, B) {
                F++;
                C.push("<a href=\"javascript:void(0);\" style=\"background-image:url(" + R + A + ".gif);\" emot=\"" + P + "," + A + "\" title=\"" + B + "\" xhev=\"" + B + "\">&nbsp;</a>");
                if (F % H == 0) C.push("<br />")
            });
            var L = H * (A + 12),
            J = Math.ceil(F / H) * (M + 12),
            O = L * 0.75;
            if (J <= O) O = "";
            G = $("<style>" + (O ? ".xheEmot div{width:" + (L + 20) + "px;height:" + O + "px;}": "") + ".xheEmot div a{width:" + A + "px;height:" + M + "px;}</style><div>" + C.join("") + "</div>").click(function(A) {
                A = A.target;
                var B = $(A);
                if (!$.nodeName(A, "A")) return;
                _this.pasteHTML("<img emot=\"" + B.attr("emot") + "\" alt=\"" + B.attr("xhev") + "\">");
                _this.hidePanel();
                return false
            }).mousedown(returnFalse);
            D.append(G);
            var S = 0,
            N = ["<ul>"],
            Q;
            $.each(arrEmots, 
            function(B, A) {
                S++;
                N.push("<li" + (P == B ? " class=\"cur\"": "") + "><a href=\"javascript:void(0);\" group=\"" + B + "\">" + A.name + "</a></li>")
            });
            if (S > 1) {
                N.push("</ul><br style=\"clear:both;\" />");
                Q = $(N.join("")).click(function(A) {
                    selEmotGroup = $(A.target).attr("group");
                    _this.exec("Emot");
                    return false
                }).mousedown(returnFalse);
                D.append(Q)
            }
            _this.showPanel(D)
        };
        this.showTable = function() {
            var E = $(htmlTable),
            C = $("#xheTableRows", E),
            K = $("#xheTableColumns", E),
            B = $("#xheTableHeaders", E),
            G = $("#xheTableWidth", E),
            D = $("#xheTableHeight", E),
            J = $("#xheTableBorder", E),
            F = $("#xheTableCellSpacing", E),
            H = $("#xheTableCellPadding", E),
            L = $("#xheTableAlign", E),
            I = $("#xheTableCaption", E),
            A = $("#xheSave", E);
            A.click(function() {
                _this.loadBookmark();
                var A = I.val(),
                U = J.val(),
                M = C.val(),
                S = K.val(),
                Q = B.val(),
                N = G.val(),
                W = D.val(),
                E = F.val(),
                P = H.val(),
                V = L.val(),
                R,
                O,
                T = "<table" + (U != "" ? " border=\"" + U + "\"": "") + (N != "" ? " width=\"" + N + "\"": "") + (W != "" ? " width=\"" + W + "\"": "") + (E != "" ? " cellspacing=\"" + E + "\"": "") + (P != "" ? " cellpadding=\"" + P + "\"": "") + (V != "" ? " align=\"" + V + "\"": "") + ">";
                if (A != "") T += "<caption>" + A + "</caption>";
                if (Q == "row" || Q == "both") {
                    T += "<tr>";
                    for (R = 0; R < S; R++) T += "<th scope=\"col\">&nbsp;</th>";
                    T += "</tr>";
                    M--
                }
                T += "<tbody>";
                for (R = 0; R < M; R++) {
                    T += "<tr>";
                    for (O = 0; O < S; O++) if (O == 0 && (Q == "col" || Q == "both")) T += "<th scope=\"row\">&nbsp;</th>";
                    else T += "<td>&nbsp;</td>";
                    T += "</tr>"
                }
                T += "</tbody></table>";
                _this.pasteHTML(T);
                _this.hidePanel();
                return false
            });
            _this.showDialog(E)
        };
        this.showAbout = function() {
            var A = $(htmlAbout);
            _this.showDialog(A)
        };
        this.addShortcuts = function(B, A) {
            B = B.toLowerCase();
            if (arrShortCuts[B] == undefined) arrShortCuts[B] = Array();
            arrShortCuts[B].push(A)
        };
        this.delShortcuts = function(A) {
            delete arrShortCuts[A]
        };
        this.uploadInit = function(jText, tourl, upext) {
            var inputname = "filedata",
            jUpload = $("<span class=\"xheUpload\"><input type=\"text\" style=\"visibility:hidden;\" tabindex=\"-1\" /><input type=\"button\" value=\"" + _this.settings.upBtnText + "\" class=\"xheBtn\" tabindex=\"-1\" /></span>"),
            jUpBtn = $(".xheBtn", jUpload),
            bHtml5Upload = _this.settings.html5Upload,
            upMultiple = bHtml5Upload ? _this.settings.upMultiple: 1;
            jText.after(jUpload);
            jUpBtn.before(jText);
            tourl = tourl.replace(/{editorRoot}/ig, editorRoot);
            if (tourl.substr(0, 1) == "!") jUpBtn.click(function() {
                bShowPanel = false;
                _this.showIframeModal("\u4e0a\u4f20\u6587\u4ef6", tourl.substr(1), setUploadMsg, null, null, 
                function() {
                    bShowPanel = true
                })
            });
            else {
                jUpload.append("<input type=\"file\"" + (upMultiple > 1 ? " multiple=\"\"": "") + " class=\"xheFile\" size=\"13\" name=\"" + inputname + "\" tabindex=\"-1\" />");
                var jFile = $(".xheFile", jUpload),
                arrMsg = [];
                jFile.change(function() {
                    startUpload(jFile[0])
                });
                setTimeout(bindDrag, 10)
            }
            function bindDrag() {
                jText.closest(".xheDialog").bind("dragenter dragover", returnFalse).bind("drop", 
                function(B) {
                    var C = B.originalEvent.dataTransfer,
                    A;
                    if (bHtml5Upload && C && (A = C.files) && A.length > 0) startUpload(A);
                    return false
                })
            }
            function startUpload(C) {
                arrMsg = [];
                var G,
                B,
                E,
                I = $("<div style=\"padding:22px 0;text-align:center;line-height:30px;\">\u6587\u4ef6\u4e0a\u4f20\u4e2d\uff0c\u8bf7\u7a0d\u5019\u2026\u2026<br /></div>"),
                D = "<img src=\"" + skinPath + "img/loading.gif\">";
                if (!bHtml5Upload || (C.nodeType && !((B = C.files) && B[0]))) {
                    if (!checkFileExt(C.value)) return;
                    I.append(D);
                    G = new _this.html4Upload(C, tourl, onUploadCallback)
                } else {
                    if (!B) B = C;
                    var H,
                    F = B.length;
                    if (F > upMultiple) {
                        alert("\u8bf7\u4e0d\u8981\u4e00\u6b21\u4e0a\u4f20\u8d85\u8fc7" + upMultiple + "\u4e2a\u6587\u4ef6");
                        return
                    }
                    for (H = 0; H < F; H++) if (!checkFileExt(B[H].fileName)) return;
                    var A = $("<div class=\"xheProgress\"><div><span>0%</span></div></div>");
                    I.append(A);
                    G = new _this.html5Upload(inputname, B, tourl, onUploadCallback, 
                    function(B) {
                        if (B.loaded >= 0) {
                            var C = Math.round((B.loaded * 100) / B.total) + "%";
                            $("div", A).css("width", C);
                            $("span", A).text(C + " ( " + formatBytes(B.loaded) + " / " + formatBytes(B.total) + " )")
                        } else A.replaceWith(D)
                    })
                }
                bShowPanel = false;
                _this.showModal("\u6587\u4ef6\u4e0a\u4f20\u4e2d(Esc\u53d6\u6d88\u4e0a\u4f20)", I, 320, 150, 
                function() {
                    bShowPanel = true;
                    G.remove()
                });
                G.start()
            }
            function checkFileExt(A) {
                if (upext == "*" || A.match(new RegExp(".(" + upext.replace(/,/g, "|") + ")$", "i"))) return true;
                else {
                    alert("\u4e0a\u4f20\u6587\u4ef6\u6269\u5c55\u540d\u5fc5\u9700\u4e3a: " + upext);
                    return false
                }
            }
            function onUploadCallback(sText, bFinish) {
                var data = Object,
                bOK = false,
                onUpload = _this.settings.onUpload;
                try {
                    data = eval("(" + sText + ")")
                } catch(ex) {}
                if (data.err == undefined || data.msg == undefined) alert(tourl + " \u4e0a\u4f20\u63a5\u53e3\u53d1\u751f\u9519\u8bef\uff01\r\n\r\n\u8fd4\u56de\u7684\u9519\u8bef\u5185\u5bb9\u4e3a: \r\n\r\n" + sText);
                else if (data.err) alert(data.err);
                else {
                    arrMsg.push(data.msg);
                    bOK = true
                }
                if (!bOK || bFinish) _this.removeModal();
                if (bFinish && bOK) {
                    setUploadMsg(arrMsg);
                    if (onUpload) onUpload(arrMsg)
                }
                return bOK
            }
            function setUploadMsg(C) {
                if (is(C, "string")) C = [C];
                var B = false,
                G,
                A = C.length,
                D,
                F,
                E = [];
                for (G = 0; G < A; G++) {
                    D = C[G];
                    F = is(D, "string") ? D: D.url;
                    if (F.substr(0, 1) == "!") {
                        B = true;
                        F = F.substr(1)
                    }
                    E.push(F)
                }
                jText.val(E.join(" "));
                if (B) jText.closest(".xheDialog").find("#xheSave").click()
            }
        };
        this.html4Upload = function(J, D, G) {
            var A = new Date().getTime(),
            I = "jUploadFrame" + A,
            H = this,
            F = $("<iframe name=\"" + I + "\" class=\"xheHideArea\" />").appendTo("body"),
            C = $("<form action=\"" + D + "\" target=\"" + I + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"xheHideArea\"></form>").appendTo("body"),
            E = $(J),
            B = E.clone().attr("disabled", "true");
            E.before(B).appendTo(C);
            this.remove = function() {
                if (H != null) {
                    B.before(E).remove();
                    F.remove();
                    C.remove();
                    H = null
                }
            };
            this.onLoad = function() {
                G($(F[0].contentWindow.document.body).text(), true)
            };
            this.start = function() {
                C.submit();
                F.load(H.onLoad)
            };
            return this
        };
        this.html5Upload = function(A, K, B, L, D) {
            var M,
            H = 0,
            C = K.length,
            G = 0,
            J = 0,
            N = this;
            for (var F = 0; F < C; F++) J += K[F].fileSize;
            this.remove = function() {
                if (M) {
                    M.abort();
                    M = null
                }
            };
            this.uploadNext = function(A) {
                if (A) {
                    G += K[H - 1].fileSize;
                    E(0)
                }
                if ((!A || (A && L(A, H == C) == true)) && H < C) I(K[H++], B, N.uploadNext, 
                function(A) {
                    E(A)
                })
            };
            this.start = function() {
                N.uploadNext()
            };
            function I(E, B, C, D) {
                M = new XMLHttpRequest(),
                upload = M.upload;
                M.onreadystatechange = function() {
                    if (M.readyState == 4) C(M.responseText)
                };
                if (upload) upload.onprogress = function(A) {
                    D(A.loaded)
                };
                else D( - 1);
                M.open("POST", B);
                M.setRequestHeader("Content-Type", "application/octet-stream");
                M.setRequestHeader("Content-Disposition", "attachment; name=\"" + A + "\"; filename=\"" + E.fileName + "\"");
                if (M.sendAsBinary) M.sendAsBinary(E.getAsBinary());
                else M.send(E)
            }
            function E(A) {
                if (D) D({
                    "loaded": G + A,
                    "total": J
                })
            }
        };
        this.showIframeModal = function(C, B, H, A, I, D) {
            var F = $("<iframe frameborder=\"0\" src=\"" + B.replace(/{editorRoot}/ig, editorRoot) + "\" style=\"width:100%;height:100%;display:none;\" /><div class=\"xheModalIfmWait\"></div>"),
            E = $(F[0]),
            G = $(F[1]);
            _this.showModal(C, F, A, I, D);
            E.load(function() {
                var A = E[0].contentWindow,
                B = $(A.document);
                A.callback = function(A) {
                    _this.removeModal();
                    H(A)
                };
                B.keydown(_this.modalEscCheck);
                E.show();
                G.remove()
            })
        };
        this.showModal = function(C, B, A, J, D) {
            if ($(".xheModal").length == 1) return false;
            var E,
            F,
            H,
            G,
            I;
            A = A ? A: _this.settings.modalWidth;
            J = J ? J: _this.settings.modalHeight;
            G = _this.settings.layerShadow;
            E = $("<div class=\"xheModal\" style=\"width:" + (A - 1) + "px;height:" + J + "px;margin-left:-" + Math.ceil(A / 2) + "px;" + (isIE && browerVer <= 7 ? "": "margin-top:-" + Math.ceil(J / 2) + "px") + "\">" + (_this.settings.modalTitle ? "<div class=\"xheModalTitle\"><span class=\"xheModalClose\" title=\"\u5173\u95ed (Esc)\"></span>" + C + "</div>": "") + "<div class=\"xheModalContent\"></div></div>").appendTo("body");
            H = $("<div class=\"xheModalOverlay\"></div>").appendTo("body");
            if (G > 0) F = $("<div class=\"xheModalShadow\" style=\"width:" + E.outerWidth() + "px;height:" + E.outerHeight() + "px;margin-left:-" + (Math.ceil(A / 2) - G - 2) + "px;" + (isIE && browerVer <= 7 ? "": "margin-top:-" + (Math.ceil(J / 2) - G - 2) + "px") + "\"></div>").appendTo("body");
            $(".xheModalContent", E).css("height", J - (_this.settings.modalTitle ? $(".xheModalTitle").outerHeight() : 0)).html(B);
            if (isIE && browerVer == 6) I = $("select:visible").css("visibility", "hidden");
            this.removeModal = function() {
                if (I) I.css("visibility", "visible");
                $(document).unbind("keydown", _this.modalEscCheck);
                E.remove();
                if (G > 0) F.remove();
                H.remove();
                if (D) D()
            };
            this.modalEscCheck = function(A) {
                if (A.which == 27) {
                    _this.removeModal();
                    return false
                }
            };
            $(document).keydown(_this.modalEscCheck);
            $(".xheModalClose", E).click(_this.removeModal);
            H.show();
            if (G > 0) F.show();
            E.show()
        };
        this.showDialog = function(B) {
            var E = $("<div class=\"xheDialog\"></div>"),
            D = $(B),
            C = $("#xheSave", D);
            if (C.length == 1) {
                D.find("input[type=text],select").keypress(function(A) {
                    if (A.which == 13) {
                        C.click();
                        return false
                    }
                });
                D.find("textarea").keydown(function(A) {
                    if (A.ctrlKey && A.which == 13) {
                        C.click();
                        return false
                    }
                });
                C.after(" <input type=\"button\" id=\"xheCancel\" value=\"\u53d6\u6d88\" />");
                $("#xheCancel", D).click(_this.hidePanel);
                if (!_this.settings.clickCancelDialog) {
                    bClickCancel = false;
                    var A = $("<div class=\"xheFixCancel\"></div>").appendTo("body").mousedown(returnFalse),
                    F = _jArea.offset();
                    A.css({
                        "left": F.left,
                        "top": F.top,
                        width: _jArea.outerWidth(),
                        height: _jArea.outerHeight()
                    })
                }
                E.mousedown(function() {
                    bDisableHoverExec = true
                })
            }
            E.append(D);
            _this.showPanel(E);
            if (!isIE) setTimeout(function() {
                E.find("input[type=text],textarea").filter(":visible").filter(function() {
                    return $(this).css("visibility") != "hidden"
                }).eq(0).focus()
            },
            10)
        };
        this.showPanel = function(A) {
            if (!ev.target) return false;
            _jPanel.empty().append(A).css("left", -999).css("top", -999);
            _jPanelButton = $(ev.target).closest("a").addClass("xheActive");
            var E = _jPanelButton.offset(),
            D = E.left,
            C = E.top;
            C += _jPanelButton.outerHeight() - 1;
            _jCntLine.css({
                "left": D + 1,
                "top": C
            }).show();
            if ((D + _jPanel.outerWidth()) > document.body.clientWidth) D -= (_jPanel.outerWidth() - _jPanelButton.outerWidth());
            var B = _this.settings.layerShadow;
            if (B > 0) _jShadow.css({
                "left": D + B,
                "top": C + B,
                "width": _jPanel.outerWidth(),
                "height": _jPanel.outerHeight()
            }).show();
            _jPanel.css("left", D).css("top", C).show();
            bQuickHoverExec = bShowPanel = true
        };
        this.hidePanel = function() {
            if (bShowPanel) {
                _jPanelButton.removeClass("xheActive");
                _jShadow.hide();
                _jCntLine.hide();
                _jPanel.hide();
                bShowPanel = false;
                if (!bClickCancel) {
                    $(".xheFixCancel").remove();
                    bClickCancel = true
                }
                bQuickHoverExec = bDisableHoverExec = false;
                lastAngle = null
            }
        };
        this.exec = function(B) {
            _this.hidePanel();
            _this.saveBookmark();
            var E = arrTools[B];
            if (!E) return false;
            if (ev == null) {
                ev = {};
                var C = _jTools.find(".xheButton[name=" + B + "]");
                if (C.length == 1) ev.target = C
            }
            if (E.e) E.e.call(_this);
            else {
                B = B.toLowerCase();
                switch (B) {
                case "cut":
                    try {
                        _doc.execCommand(B);
                        if (!_doc.queryCommandSupported(B)) throw "Error"
                    } catch(A) {
                        alert("\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u4f7f\u7528\u526a\u5207\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl + X)\u6765\u5b8c\u6210")
                    }
                    break;
                case "copy":
                    try {
                        _doc.execCommand(B);
                        if (!_doc.queryCommandSupported(B)) throw "Error"
                    } catch(A) {
                        alert("\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u4f7f\u7528\u590d\u5236\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl + C)\u6765\u5b8c\u6210")
                    }
                    break;
                case "paste":
                    try {
                        _doc.execCommand(B);
                        if (!_doc.queryCommandSupported(B)) throw "Error"
                    } catch(A) {
                        alert("\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u4f7f\u7528\u7c98\u8d34\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl + V)\u6765\u5b8c\u6210")
                    }
                    break;
                case "pastetext":
                    if (window.clipboardData) _this.pasteText(window.clipboardData.getData("Text", true));
                    else _this.showPastetext();
                    break;
                case "blocktag":
                    var G = [];
                    $.each(arrBlocktag, 
                    function(B, A) {
                        G.push({
                            s: "<" + A.n + ">" + A.t + "</" + A.n + ">",
                            v: "<" + A.n + ">",
                            t: A.t
                        })
                    });
                    _this.showMenu(G, 
                    function(A) {
                        _this._exec("formatblock", A)
                    });
                    break;
                case "fontface":
                    var F = [];
                    $.each(arrFontname, 
                    function(B, A) {
                        A.c = A.c ? A.c: A.n;
                        F.push({
                            s: "<span style=\"font-family:" + A.c + "\">" + A.n + "</span>",
                            v: A.c,
                            t: A.n
                        })
                    });
                    _this.showMenu(F, 
                    function(A) {
                        _this._exec("fontname", A)
                    });
                    break;
                case "fontsize":
                    var D = [];
                    $.each(arrFontsize, 
                    function(B, A) {
                        D.push({
                            s: "<span style=\"font-size:" + A.s + ";\">" + A.t + "(" + A.s + ")</span>",
                            v: B + 1,
                            t: A.t
                        })
                    });
                    _this.showMenu(D, 
                    function(A) {
                        _this._exec("fontsize", A)
                    });
                    break;
                case "fontcolor":
                    _this.showColor(function(A) {
                        _this._exec("forecolor", A)
                    });
                    break;
                case "backcolor":
                    _this.showColor(function(A) {
                        if (isIE) _this._exec("backcolor", A);
                        else {
                            setCSS(true);
                            _this._exec("hilitecolor", A);
                            setCSS(false)
                        }
                    });
                    break;
                case "align":
                    _this.showMenu(menuAlign, 
                    function(A) {
                        _this._exec(A)
                    });
                    break;
                case "list":
                    _this.showMenu(menuList, 
                    function(A) {
                        _this._exec(A)
                    });
                    break;
                case "link":
                    _this.showLink();
                    break;
                case "img":
                    _this.showImg();
                    break;
                case "flash":
                    _this.showEmbed("Flash", htmlFlash, "application/x-shockwave-flash", "clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000", " wmode=\"opaque\" quality=\"high\" menu=\"false\" play=\"true\" loop=\"true\" allowfullscreen=\"true\"", _this.settings.upFlashUrl, _this.settings.upFlashExt);
                    break;
                case "media":
                    _this.showEmbed("Media", htmlMedia, "application/x-mplayer2", "clsid:6bf52a52-394a-11d3-b153-00c04f79faa6", " enablecontextmenu=\"false\" autostart=\"false\"", _this.settings.upMediaUrl, _this.settings.upMediaExt);
                    break;
                case "emot":
                    _this.showEmot();
                    break;
                case "table":
                    _this.showTable();
                    break;
                case "source":
                    _this.toggleSource();
                    break;
                case "print":
                    _win.print();
                    break;
                case "fullscreen":
                    _this.toggleFullscreen();
                    break;
                default:
                    _this._exec(B);
                    break
                }
            }
            ev = null
        };
        this._exec = function(B, C, A) {
            if (!A) _this.focus();
            var D;
            if (C != undefined) D = _doc.execCommand(B, false, C);
            else D = _doc.execCommand(B, false, null);
            return D
        };
        function loadReset() {
            setTimeout(_this.setSource, 10)
        }
        function saveResult() {
            _this.getSource()
        }
        function cleanWordPaste() {
            if (isIE && !bSource) {
                var B,
                A = _jTempIframe[0].contentWindow.document.body;
                A.innerHTML = "";
                A.createTextRange().execCommand("Paste");
                B = A.innerHTML;
                if (!B.match(/mso-|MsoNormal/i)) return true;
                if (B.indexOf("&nbsp;") == 0) B = B.substring(6);
                B = _this.cleanHTML(B);
                B = _this.formatXHTML(B);
                B = _this.cleanWord(B);
                _this.pasteHTML(B);
                return false
            }
        }
        function setCSS(B) {
            try {
                _this._exec("styleWithCSS", B, true)
            } catch(A) {
                try {
                    _this._exec("useCSS", !B, true)
                } catch(A) {}
            }
        }
        function setOpts() {
            if (bInit && !bSource) {
                setCSS(false);
                try {
                    _this._exec("enableObjectResizing", true, true)
                } catch(A) {}
                if (isIE) {
                    try {
                        _this._exec("BackgroundImageCache", true, true)
                    } catch(A) {}
                }
            }
        }
        function forcePtag(A) {
            if (bSource || A.which != 13 || A.shiftKey || A.ctrlKey || A.altKey) return true;
            var B = _this.getParent("p,h1,h2,h3,h4,h5,h6,pre,address,div,li");
            if (B.is("li")) return true;
            if (_this.settings.forcePtag) {
                if (B.length == 0) _this._exec("formatblock", "<p>")
            } else {
                _this.pasteHTML("<br />");
                return false
            }
        }
        function fixFullHeight() {
            if (!isMozilla && !isSafari) {
                if (bFullscreen) _jArea.height("100%").css("height", _jArea.outerHeight() - _jTools.outerHeight());
                if (isIE) _jTools.hide().show()
            }
        }
        function fixAppleSel(A) {
            A = A.target;
            if (A.tagName.match(/(img|embed)/i)) {
                var C = _this.getSel(),
                B = _this.getRng();
                B.selectNode(A);
                C.removeAllRanges();
                C.addRange(B)
            }
        }
        function xheAttr(B, C, A) {
            if (!C) return false;
            var D = "_xhe_" + C;
            if (A) B.attr(C, A).removeAttr(D).attr(D, A);
            return B.attr(D) || B.attr(C)
        }
        function clickCancelPanel() {
            if (bClickCancel) _this.hidePanel()
        }
        function checkShortcuts(D) {
            if (bSource) return true;
            var F = D.which,
            E = specialKeys[F],
            A = E ? E: String.fromCharCode(F).toLowerCase();
            sKey = "";
            sKey += D.ctrlKey ? "ctrl+": "";
            sKey += D.altKey ? "alt+": "";
            sKey += D.shiftKey ? "shift+": "";
            sKey += A;
            var B = arrShortCuts[sKey],
            C;
            for (C in B) {
                C = B[C];
                if ($.isFunction(C)) {
                    if (C.call(_this) === false) return false
                } else {
                    _this.exec(C);
                    return false
                }
            }
        }
        function is(C, A) {
            var B = typeof(C);
            if (!A) return B != "undefined";
            if (A == "array" && (C.hasOwnProperty && C instanceof Array)) return true;
            return B == A
        }
        function getLocalUrl(F, E) {
            var B = location.protocol,
            C = location.hostname,
            A = location.port,
            D = location.pathname.replace(/\\/g, "/").replace(/[^\/]+$/i, "");
            A = (A == "") ? "80": A;
            F = $.trim(F);
            if (B == "file:") E = "abs";
            if (E != "abs") F = F.replace(new RegExp(B + "\\/\\/" + C.replace(/\./g, "\\.") + "(?::" + A + ")" + (A == "80" ? "?": "") + "(/|$)", "i"), "/");
            if (E == "rel") F = F.replace(new RegExp("^" + D.replace(/([\/\.\+\[\]\(\)])/g, "\\$1"), "i"), "");
            if (E != "rel") if (!F.match(/^((https?|file):\/\/|\/)/i)) F = D + F;
            if (E == "abs") if (!F.match(/(https?|file):\/\//i)) F = B + "//" + location.host + F;
            return F
        }
        function formatBytes(B) {
            var C = ["Byte", "KB", "MB", "GB", "TB", "PB"],
            A = Math.floor(Math.log(B) / Math.log(1024));
            return (B / Math.pow(1024, Math.floor(A))).toFixed(2) + C[A]
        }
        function returnFalse() {
            return false
        }
    };
    $(function() {
        $.fn.oldVal = $.fn.val;
        $.fn.val = function(B) {
            var C = this,
            A;
            if (B === undefined) if (this[0] && (A = this[0].xheditor)) return A.getSource();
            else return C.oldVal(B);
            return this.each(function() {
                if (A = this.xheditor) A.setSource(B);
                else C.oldVal(B)
            })
        };
        $("textarea").each(function() {
            var A = $(this),
            B = A.attr("class").match(/(?:^|\s)xheditor(?:\-(m?full|simple|mini|zbj))?(?:\s|$)/i);
            if (B) A.xheditor(B[1] ? {
                tools: B[1]
            }: null)
        })
    })
}
editTools(jQuery)